package com.jjh.dao.impl;

import com.jjh.consts.Properties;
import com.jjh.winterframework.annatation.Component;
import com.jjh.dao.ShopDao;
import com.jjh.pojo.Shop;
import com.jjh.util.FileUtils;
import com.jjh.util.PageBody;

import java.io.IOException;
import java.util.List;
@Component
public class ShopDaoImpl implements ShopDao {

    //private static final String shopPah ="E:\\EeleMa\\src\\main\\resources\\shops.txt";

    /**
     * 分页查询商家
     *
     * @param page 页数
     * @param size 尺寸
     * @return 分页结果实体
     */
    @Override
    public PageBody page(int page, int size) {

        List<Object> shopList = FileUtils.pageList(page, size, Properties.SHOP_PATH, Shop.class);


        PageBody pageBody = new PageBody();
        try {
            int total = FileUtils.getFileRow(Properties.SHOP_PATH);
            pageBody.setTotal(total);
            pageBody.setCurrntPage(page);
            pageBody.setSize(size);
            pageBody.setResults(shopList);
            pageBody.setPageSize(total/size+1);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return pageBody;
    }
}
